//
//  SYBaiBanTabView.m
//  SanYiTeaching
//
//  Created by 郑浩然 on 2019/12/25.
//  Copyright © 2019年 SanYi. All rights reserved.
//

#import "SYBaiBanTabView.h"
#import "UIView+Category.h"
#import "SYBaiBanModel.h"

@interface SYBaiBanTabView ()
@property (weak, nonatomic) IBOutlet UICollectionView *curCollectionView;
@property (strong, nonatomic) NSMutableArray *dataArr;
@property (strong, nonatomic) UIButton *selectBtn;
@property (strong, nonatomic) UIButton *contSelectBtn;

@end



@implementation SYBaiBanTabView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

//- (instancetype)initWithFrame:(CGRect)frame {
//    self = [super initWithFrame:frame];
//    if (self) {
//        [self initSubView];
//        self.backgroundColor = [UIColor redColor];
//    }
//    return self;
//}
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self initSubView];
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}

//- (instancetype)init {
//    self = [super init];
//    if (self) {
//        [self initSubView];
//        self.backgroundColor = [UIColor clearColor];
//    }
//
//    return self;
//}


- (void)initSubView {
    
    _dataArr = [SYBaiBanModel iconImageArr];
    CGFloat w = 0.1;
    UIButton *contBtn = nil;
    for (NSInteger i = 0; i<_dataArr.count ; i++) {
        SYBaiBanModel *bbModel = _dataArr[i];
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setImage:[UIImage imageNamed:bbModel.iconImage] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:bbModel.selectIconImage] forState:UIControlStateSelected];
        [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        btn.tag = i;
        [self addSubview:btn];
        
        
        if (i == 0) {
            contBtn = btn;
            
            [btn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.mas_left);
                make.top.equalTo(self.mas_top);
                make.width.equalTo(self).multipliedBy(w);
                make.height.mas_equalTo(40);
            }];
        } else {
            if (i == 2) {//默认选择画笔
                self.selectBtn = btn;
                self.selectBtn.selected = YES;
                self.contSelectBtn = btn;
            }
            [btn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(contBtn.mas_right);
                make.top.equalTo(self.mas_top);
                make.width.equalTo(self).multipliedBy(w);
                make.height.mas_equalTo(40);
            }];
            contBtn = btn;
        }
        
    }
}

- (void)btnClick:(UIButton *)btn {
//    if (self.selectBtn == btn) {
//        return;
//    }
//    3 画板 选择画板得时候如果是画笔、文本、滑动、清除。画笔选中色不变。
    NSInteger index = btn.tag;
    if (index == 0 || index == 3|| index == 7|| index == 8|| index == 9|| index == 10) {
        
    } else {
        self.selectBtn.selected = NO;
        self.selectBtn = btn;
        self.selectBtn.selected = YES;
    }
    
    
    
    
    if (self.block) {
        self.block(index,btn);
    }
}

@end
